#!/usr/bin/perl

use Modern::Perl;
use Test::More tests => 8;
use File::Slurp;
use Log::Log4perl qw( :easy );

require AEF::AEFSearch;

Log::Log4perl->easy_init($INFO);

my @files = qw/ConsoleApp Dll Library TerminalApp/;
my @versions = qw/1.4.00 1.2.0.2 1.2.00 33.4.00/;
for(my $i = 0; $i < @files; $i++) 
{
    my ($filename, $expected) = ($files[$i], $versions[$i]);
	my $file = "./t/AEF_test_files/$filename.AEF";
	my $data = read_file($file, binmode => ':raw');

	my $search = AEF::AEFSearch->new();
	my $version = $search->GetVersion($data);
    is($version, $expected, "Checking $filename.AEF version is $expected");
}

my @pe_files = qw/ConsoleApp Dll TerminalApp/;
my @pe_versions = qw/1.4.00 1.2.0.2 33.4.00/;
for(my $i = 0; $i < @pe_files; $i++) 
{
    my ($filename, $expected) = ($pe_files[$i], $pe_versions[$i]);
	my $file = "./t/AEF_test_files/$filename.AEF";
	my $data = read_file($file, binmode => ':raw');

	my $search = AEF::AEFSearch->new(IgnoreNonPEFiles => 1);
	my $version = $search->GetVersion($data);
    is($version, $expected, "Checking $filename.AEF version is $expected");
}

{
	# check that we don't find the version for the Library since it's
	# not a PE file
    my $filename = 'Library';
	my $file = "./t/AEF_test_files/$filename.AEF";
	my $data = read_file($file, binmode => ':raw');

	my $search = AEF::AEFSearch->new(IgnoreNonPEFiles => 1);
	my $version = $search->GetVersion($data);
	is($version, "", "Checking no version found for library");
}

#done_testing();

